﻿@model HQPad.Models.SchoolAccessModel

@if (Model.Records.Count() > 0)
{

    <div class="sidebar-container sidebar-bottom-margin">
        <h2>School access</h2>
        <table>
            <tbody>
                @foreach (var item in Model.Records.OrderBy(r => r.SchoolName).ThenBy(r => r.Access))
                {
                    <tr>
                        <td>@Html.Raw(item.SchoolName)</td>
                        <td @(item.Access == "Sorceror" ? "class=sorcerer" : item.Access == "Wizard" ? "class=wizard" : "class=mage") >
                            @Html.Raw(item.Access)

@*                            @if (item.SpecialistAllowed && item.PrimaryAllowed)
                            {
                                <span>(primary, specialist)</span>
                            }*@
                            @if (item.PrimaryAllowed)
                            {
                                <span>(primary)</span>
                            }
@*                            else if (item.SpecialistAllowed)
                            {
                                <span>(specialist)</span>
                            }*@
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
}

@if (Model.Status.Count() > 0)
{
    <div class="sidebar-container sidebar-bottom-margin">
        <h2>Learnt spells</h2>

        <p>Known spells available and learnt.</p>
    
        @using (Html.BeginForm("Magic", "Character", FormMethod.Post, new { @name = "setStatusForm", @id = "setStatusForm" }))
        {
            <table class="school-status">
                <thead>
                    <tr>
                        <th>Spells</th>
                        <th>Level 1-8</th>
                        <th>Level 9</th>
                        <th>Level 10</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td class="total-label">Available</td>
                        <td class="total-available">
                            @if (Model.Status.Where(s => s.Level == HQPad.Helpers.SchoolStatusAssignmentType.Level1to8).Any())
                            {
                                @Html.Raw(Model.Status.Where(s => s.Level == HQPad.Helpers.SchoolStatusAssignmentType.Level1to8).First().AvailableToLearn.ToString())
                            }
                        </td>
                        <td class="total-available">
                            @if (Model.Status.Where(s => s.Level == HQPad.Helpers.SchoolStatusAssignmentType.Level9).Any())
                            {
                                @Html.Raw(Model.Status.Where(s => s.Level == HQPad.Helpers.SchoolStatusAssignmentType.Level9).First().AvailableToLearn.ToString())
                            }
                        </td>
                        <td class="total-available">
                            @if (Model.Status.Where(s => s.Level == HQPad.Helpers.SchoolStatusAssignmentType.Level10).Any())
                            {
                                @Html.Raw(Model.Status.Where(s => s.Level == HQPad.Helpers.SchoolStatusAssignmentType.Level10).First().AvailableToLearn.ToString())
                            }
                        </td>
                    </tr>
@*                    @foreach (var item in Model.Status.GetGroupedStatusAssignments())
                    {
                        <tr>
                            <td class="access-label">@Html.Raw(item.SchoolName)</td>
                            
                            @foreach (var typeItem in item.Items.OrderBy(s => s.Type))
                            {
                                var fieldName = string.Format("status_{0}_{1}", item.SchoolSlug, Enum.GetName(typeof(HQPad.Helpers.SchoolStatusAssignmentType), typeItem.Type));
                                <td>
                                    @Html.TextBox(fieldName, typeItem.Status.ToString())
                                    <div>@Html.ValidationMessage(fieldName, new { @class = "error" })</div>
                                </td>
                            }
                        </tr>
                    }*@
                    <tr>
                        <td class="total-label">Spent</td>
                        <td class="total-spent">
                            @if (Model.Status.Where(s => s.Level == HQPad.Helpers.SchoolStatusAssignmentType.Level1to8).Any())
                            {                            
                                @Html.Raw(Model.Status.Where(s => s.Level == HQPad.Helpers.SchoolStatusAssignmentType.Level1to8).First().Learnt.ToString())
                            }</td>
                        <td class="total-spent">
                            @if (Model.Status.Where(s => s.Level == HQPad.Helpers.SchoolStatusAssignmentType.Level9).Any())
                            {
                                @Html.Raw(Model.Status.Where(s => s.Level == HQPad.Helpers.SchoolStatusAssignmentType.Level9).First().Learnt.ToString())
                            }
                        </td>
                        <td class="total-spent">
                            @if (Model.Status.Where(s => s.Level == HQPad.Helpers.SchoolStatusAssignmentType.Level10).Any())
                            {
                                @Html.Raw(Model.Status.Where(s => s.Level == HQPad.Helpers.SchoolStatusAssignmentType.Level10).First().Learnt.ToString())
                            }
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td colspan="3" class="update-button">
                            <input type="submit" value="Update" id="setStatus" name="setStatus" />
                            <div>@Html.ValidationMessage("generalError", new { @class = "error" })</div>
                        </td>
                    </tr>
                </tbody>
            </table>
        }
    </div>
}
    
<div class="sidebar-container">
    <h2>School selection</h2>

    @using (Html.BeginForm("Magic", "Character", FormMethod.Post, new { @name = "setSchoolsForm", @id = "setSchoolsForm" }))
    {
        <table>
            <tbody>
                @foreach (var item in Model.AccessItems)
                {
                    <tr>
                        <td class="access-label">@Html.Label("access_" + item.AccessSlug, item.AccessName)</td>
                        <td>
                            @Html.DropDownList("access_" + item.AccessSlug, new SelectList(Model.Schools, "Slug", "Name", item.SchoolSlug), "none")
                            @Html.ValidationMessage("access_" + item.AccessSlug, new { @class = "error" })
                        </td>
                    </tr>
                }
                <tr>
                    <td></td>
                    <td><input type="submit" value="Update" id="setSchools" name="setSchools" /></td>
                </tr>
            </tbody>
        </table>
    }
</div>